package com.csu.petstore.exception.Validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class IsPhoneValidator implements ConstraintValidator<IsPhone,String> {

    private boolean required = false;
    @Override
    public void initialize(IsPhone constraintAnnotation) {
        // 在这里进行初始化操作
        required = constraintAnnotation.required();
        // 添加你的初始化代码
    }
    //判断是否符合电话格式
    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        if (required){
            return ValidatorUtil.isMobile(s);
        }else{
            return s.isEmpty();
        }
    }
}
